﻿Imports System.Runtime.InteropServices
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Windows.Forms

<Serializable()>
Public Class ReportMatadata
    Implements IComparable(Of ReportMatadata)
    Implements IEquatable(Of ReportMatadata)

    ''' <summary>
    ''' The unique, identifier of the report
    ''' </summary>
    ''' <remarks>
    ''' Each report must have an integer unique identifier
    ''' </remarks>
    Public Property ReportKey As String

    ''' <summary>
    ''' the name of the assembly that the report type resides in
    ''' </summary>
    ''' <remarks></remarks>
    Public Property ReportAssemblyName As String

    ''' <summary>
    ''' Class that handles before and after the report is shown
    ''' </summary>
    Public Property ReportService As IReportService

    ''' <summary>
    ''' Fully qualified resource path of the report definition file
    ''' </summary>
    Public Property FullyQualifiedResourcePath As String


    ''' <summary>
    ''' Fully qualified Operating System path of the report definition file.
    ''' If this has a value,  FullyQualifiedResourcePath should not have a value
    ''' </summary>
    Public Property FullyOSPath As String

    ''' <summary>
    ''' The order (1st, 2nd, etc) that this report is shown on a menu
    ''' </summary>
    Public Property DisplayOrder As Integer

    ''' <summary>
    ''' The Category of the report
    ''' </summary>
    Public Property Category As String

    ''' <summary>
    ''' List of Criteria of this report
    ''' </summary>
    Public Property Criteria As List(Of CriterionMetadata) = New List(Of CriterionMetadata)

    ''' <summary>
    ''' The name of the report, as it will appear on a menu
    ''' </summary>
    Public Property DisplayName As String


    Public Function getCriterion(ByVal critname As String) As CriterionMetadata

        Return Me.Criteria.FirstOrDefault(Function(x)
                                              Return x.Name = critname
                                          End Function)

    End Function


   

    Public Function CompareTo(ByVal other As ReportMatadata) As Integer _
            Implements System.IComparable(Of ReportMatadata).CompareTo

        Return Me.DisplayOrder.CompareTo(other.DisplayOrder)

    End Function

    Public Overrides Function Equals(ByVal obj As Object) As Boolean

        If obj Is Nothing Then Return False
        Return Me.EqualsT(CType(obj, ReportMatadata))

    End Function

    Public Function EqualsT(ByVal other As ReportMatadata) As Boolean _
            Implements System.IEquatable(Of ReportMatadata).Equals

        Return Me.ReportKey.Equals(other.ReportKey)

    End Function
End Class

